package com.lagou.rpc.consumer.handler;

import com.lagou.rpc.consumer.msg.InbountMsg;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 客户端处理类
 * 1.发送消息
 * 2.接收消息
 */
public class RpcClientHandler extends SimpleChannelInboundHandler<String>{
    InbountMsg<String> inbountMsg;

    public RpcClientHandler(InbountMsg<String> inbountMsg) {
        this.inbountMsg = inbountMsg;
    }


    /**
     * 通道读取就绪事件
     *
     * @param channelHandlerContext
     * @param msg
     * @throws Exception
     */
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, String msg) throws Exception {
        inbountMsg.receive(msg);
    }
}
